package utilizadores;

import interfaces.SugestoesEstabelecimentosService;

import javax.swing.JFrame;
import javax.swing.JLabel;

import java.awt.Color;

import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;

import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class FormulariosDetalhe {

    private JFrame frame;
    private JTextField inputTextName;
    private JTextField inputTextCity;
    private JTextField inputTextSchool;
    private JTextField inputTextFieldEmail;
    private JTextField followerOne;
    private JTextField followerTwo;
    private JTextField followerThree;

    public String nome, email, escola;
    public String seguidores[] = new String[3];

    public FormulariosDetalhe(String nome, String email, String escola, String[] storeNameDBContent) {

        this.nome = nome;
        this.email = email;
        this.escola = escola;
        this.seguidores = storeNameDBContent;
        initialize();
    }

    private void initialize() {

        frame = new JFrame("Pesquisa de utilizador");
        frame.getContentPane().setBackground(new Color(220, 220, 220));
        frame.setBounds(100, 100, 560, 460);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.getContentPane().setLayout(null);

        JLabel labelName = new JLabel("NOME:");
        labelName.setBounds(10, 10, 38, 24);
        frame.getContentPane().add(labelName);

        inputTextName = new JTextField();
        inputTextName.setText(nome);
        inputTextName.setEditable(false);
        inputTextName.setBounds(49, 10, 485, 24);
        frame.getContentPane().add(inputTextName);
        inputTextName.setColumns(10);

        JLabel labelCity = new JLabel("CIDADE:");
        labelCity.setBounds(10, 46, 50, 24);
        frame.getContentPane().add(labelCity);

        inputTextCity = new JTextField();
        inputTextCity.setText("Undefined");
        inputTextCity.setEditable(false);
        inputTextCity.setColumns(10);
        inputTextCity.setBounds(58, 46, 144, 24);
        frame.getContentPane().add(inputTextCity);

        JLabel labelEmail = new JLabel("E-mail:");
        labelEmail.setBounds(10, 81, 50, 24);
        frame.getContentPane().add(labelEmail);

        inputTextFieldEmail = new JTextField();
        inputTextFieldEmail.setEditable(false);
        inputTextFieldEmail.setText(email);
        inputTextFieldEmail.setColumns(10);
        inputTextFieldEmail.setBounds(58, 83, 286, 24);
        frame.getContentPane().add(inputTextFieldEmail);

        JLabel labelSchool = new JLabel("ESCOLA:");
        labelSchool.setBounds(227, 46, 50, 24);
        frame.getContentPane().add(labelSchool);

        inputTextSchool = new JTextField();
        inputTextSchool.setText(escola);
        inputTextSchool.setEditable(false);
        inputTextSchool.setColumns(10);
        inputTextSchool.setBounds(278, 46, 256, 24);
        frame.getContentPane().add(inputTextSchool);

        JButton buttonSaveDetails = new JButton("Guardar Detalhes");
        buttonSaveDetails.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        buttonSaveDetails.setEnabled(false);
        buttonSaveDetails.setBackground(new Color(30, 144, 255));

        buttonSaveDetails.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                System.err.println("CLICK!");
            }
        });
        buttonSaveDetails.setBounds(354, 82, 180, 24);
        frame.getContentPane().add(buttonSaveDetails);

        JButton buttonChangePhoto = new JButton("Alterar Foto");
        buttonChangePhoto.setEnabled(false);
        buttonChangePhoto.setBackground(new Color(30, 144, 255));

        buttonChangePhoto.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {

                System.err.println("Change Photo");
            }
        });
        buttonChangePhoto.setBounds(10, 330, 180, 24);
        frame.getContentPane().add(buttonChangePhoto);

        JButton buttonSuggestions = new JButton("Sugest\u00F5es");
        buttonSuggestions.setBackground(new Color(30, 144, 255));
        buttonSuggestions.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.err.println("CALL NEW WINDOW");

                if(inputTextFieldEmail.getText().toString() != null) {
                    SugestoesEstabelecimentosService.getInstance().verSugestoes(inputTextFieldEmail.getText().toString());
                }

            }
        });
        buttonSuggestions.setBounds(184, 378, 160, 24);
        frame.getContentPane().add(buttonSuggestions);

        JPanel imagePanel = new JPanel();
        imagePanel.setBounds(10, 139, 180, 180);
        frame.getContentPane().add(imagePanel);

        JLabel labelFollowedBy = new JLabel("Seguido por:");
        labelFollowedBy.setFont(new Font("Tahoma", Font.BOLD, 14));
        labelFollowedBy.setBounds(278, 117, 95, 24);
        frame.getContentPane().add(labelFollowedBy);

        JPanel panel = new JPanel();
        panel.setBounds(278, 139, 256, 180);
        frame.getContentPane().add(panel);
        panel.setLayout(null);

        followerOne = new JTextField();
        followerOne.setEditable(false);
        followerOne.setBounds(0, 0, 216, 24);
        followerOne.setText(seguidores[0]);
        panel.add(followerOne);

        JButton buttonFollowerOne = new JButton("");
        buttonFollowerOne.setBounds(226, 0, 30, 24);
        panel.add(buttonFollowerOne);

        followerTwo = new JTextField();
        followerTwo.setEditable(false);
        followerTwo.setColumns(10);
        followerTwo.setBounds(0, 26, 216, 24);
        followerTwo.setText(seguidores[1]);
        panel.add(followerTwo);

        JButton buttonFollowerTwo = new JButton("");
        buttonFollowerTwo.setBounds(226, 26, 30, 24);
        panel.add(buttonFollowerTwo);

        followerThree = new JTextField();
        followerThree.setEditable(false);
        followerThree.setColumns(10);
        followerThree.setBounds(0, 52, 216, 24);
        followerThree.setText(seguidores[2]);
        panel.add(followerThree);

        JButton buttonFollowerThree = new JButton("");
        buttonFollowerThree.setBounds(226, 52, 30, 24);
        panel.add(buttonFollowerThree);

        frame.setVisible(true);
        frame.setResizable(false);

    }

}
